<?php
class UploadManager
{
    
    public static function upload($file, $chemin, $tailleMax)
    {
        if (isBonneTaille($file, $tailleMax))
        {
            echo $chemin.$file['tmp_name'];
            if (move_uploaded_file($file['tmp_name'], $chemin.$file['tmp_name']))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
        //Nom du fichier sans l'extension
    }
    
    public static function uploadImage($file, $chemin, $tailleMax)
    {
        $lesFormatsValides = array('png', 'jpg', 'gif');
        $extension = explode('.', $file['name']);
        if (self::isBonFormat($extension[1], $lesFormatsValides))
        {
            return self::upload($file, $chemin, $tailleMax);
        }
        else
        {
            return false;
        }
    }
    
    public static function isBonFormat($leFormat, $lesFormatsValides)
    {
        foreach ($lesFormatsValides as $formatValide)
        {
            if ($formatValide == $leFormat )
            {
                return true;
            }
        }
        return false;
    }
    
    public static function isBonneTaille($file, $tailleMax)
    {
      $tailleImg = filesize($file['tmp_name']); 
      if ($tailleImg <= $tailleMax)
          return true;
      else
          return false;
    }
}